//
//  SexViewController.m
//  FKGW
//
//  Created by song ce on 2017/2/18.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "SexViewController.h"

@interface SexViewController ()
@property (weak, nonatomic) IBOutlet UIButton *manBtn;
@property (weak, nonatomic) IBOutlet UIButton *womanBtn;
@property(nonatomic,copy)NSString *sex;
@end

@implementation SexViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if(!ISNOTNEEDMESSAGEBTN){
        self.isNeedMessageItem = YES;
    }

    
    if([USERSEX isEqualToString:@"男"]){
        [self man:self.manBtn];
    }else{
        [self woman:self.womanBtn];
    }

}

- (IBAction)man:(UIButton *)sender {
        [sender setImage:[UIImage imageNamed:@"icon_xuanzhong"] forState:UIControlStateNormal];
        [self.womanBtn setImage:[UIImage imageNamed:@"icon_weixuanzhong"] forState:UIControlStateNormal];
        self.sex = @"1";

}
- (IBAction)woman:(UIButton *)sender {
    [sender setImage:[UIImage imageNamed:@"icon_xuanzhong"] forState:UIControlStateNormal];
    [self.manBtn setImage:[UIImage imageNamed:@"icon_weixuanzhong"] forState:UIControlStateNormal];
     self.sex = @"0";
}
- (IBAction)commite:(UIButton *)sender {
    if(!self.sex.length){
        [MBProgressHUD showTipMessageInWindow:@"请选择性别"];
        return;
    }
    //修改用户名接口
    NSDictionary *paramDic = @{@"userId":USERID,
                               @"sex":self.sex};
    __weak typeof(self)  weakSelf = self;
    [Tools AFNetworkingRequestTypePostWithUrl:CHANGSEX paramters:paramDic afterResultBlock:^(NSDictionary *resultDic) {
        DLog(@"设置性别--%@",resultDic);
        if([resultDic[@"flag"] isEqualToString:@"true"]){
            NSDictionary *dataDic = resultDic[@"data"];
            if([dataDic isKindOfClass:[NSNull class]]) return ;
            if([dataDic[@"status"] isEqualToString:@"true"]){
                [MBProgressHUD showTipMessageInWindow:@"性别设置成功"];
                [weakSelf performSelector:@selector(popToSettingVc) withObject:nil afterDelay:1];
            }else{
                if(dataDic[@"errorString"]){
                    [MBProgressHUD showTipMessageInWindow:dataDic[@"errorString"]];
                }
            }
        }else{
            if(resultDic[@"errorString"]){
                [MBProgressHUD showTipMessageInWindow:resultDic[@"errorString"]];
            }
        }
    }];
}

-(void)popToSettingVc{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
